﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Schema;

namespace Wix.Aura.Common {
	public abstract class Serializable : IXmlSerializable {
		public void Serialize(Stream stream) {
			XmlSerializer serializer = new XmlSerializer(this.GetType());

			XmlWriterSettings settings = new XmlWriterSettings();
			settings.Indent = true;
			settings.NewLineChars = Environment.NewLine;
			settings.IndentChars = "\t";

			using (XmlWriter writer = XmlTextWriter.Create(stream, settings)) {
				XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
				ns.Add(string.Empty, "http://schemas.microsoft.com/Wix/2006/wi");
				serializer.Serialize(writer, this, ns);
			}
		}


		public abstract XmlSchema GetSchema();

		public abstract void ReadXml(XmlReader reader);

		public abstract void WriteXml(XmlWriter writer);
	}
}
